class Solution
{
private:
    typedef pair<TreeNode *, unsigned int> PTU;

public:
    int widthOfBinaryTree(TreeNode *root)
    {
        if (!root)
            return 0;
        queue<PTU> q;
        q.push({root, 1});
        unsigned int ans = 1;
        unsigned int num = 1;
        while (q.size())
        {
            cout << q.back().second << ' ' << q.front().second << endl;
            ans = max(ans, q.back().second - q.front().second + 1);
            while (num--)
            {
                auto tt = q.front();
                TreeNode *tmp_tree = tt.first;
                unsigned int i = tt.second;
                q.pop();

                if (tmp_tree->left)
                    q.push({tmp_tree->left, i * 2});
                // cout << 1 << endl;
                if (tmp_tree->right)
                    q.push({tmp_tree->right, i * 2 + 1});
            }
            num = q.size();
        }
        return ans;
    }
};